# src/plot_benchmark.py
import json, matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

with open("data/benchmark.json") as f:
    r = json.load(f)

# 画一张简单结果卡片
plt.figure(figsize=(6, 3))
text = f"总区块: {r['total_blocks']}\n" \
       f"总时间: {r['total_time_s']} s\n" \
       f"平均延迟: {r['avg_latency_ms']} ms\n" \
       f"峰值 TPS: {r['peak_tps']}\n" \
       f"链大小: {r['chain_size_bytes']//1024} KB"
plt.text(0.5, 0.5, text, ha='center', va='center', fontsize=12, transform=plt.gca().transAxes)
plt.axis('off')
plt.savefig("docs/fig_benchmark.png", dpi=300)
print("性能结果图已保存到 docs/fig_benchmark.png")